package org.elephantt.webby.example.webapp;

import org.elephantt.webby.*;

import javax.servlet.ServletConfig;

public class AppDispatcherServlet extends DispatcherServlet {
  private static final long serialVersionUID = -2519041667420479484L;

  @Override
  public Dispatcher createDispatcher(ServletConfig config) {
    RouteRequestMapper mapper = new RouteRequestMapper();
    SiteController siteController = new SiteController();
    mapper.addRoute(HttpMethod.GET, "/", siteController, "home");
    mapper.addRoute(HttpMethod.GET, "/person/:urlname", siteController, "person");
    mapper.addRoute(HttpMethod.POST, "/create_person", siteController, "createPerson");

    Dispatcher dispatcher = new Dispatcher(mapper);
    dispatcher.registerResponder(JspView.class, new JspViewResponder("/jsp/"));
    return dispatcher;
  }
}
